home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / fortran / f2c-9510.000 / f2c-9510 / f2c-951007-libs-1.1 / src / lex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-07  |  32.3 KB  |  1,677 lines

  1. /****************************************************************
  2. Copyright 1990, 1992 - 1995 by AT&T Bell Laboratories and Bellcore.
  3.  
  4. Permission to use, copy, modify, and distribute this software
  5. and its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the names of AT&T Bell Laboratories or
  10. Bellcore or any of their entities not be used in advertising or
  11. publicity pertaining to distribution of the software without
  12. specific, written prior permission.
  13.  
  14. AT&T and Bellcore disclaim all warranties with regard to this
  15. software, including all implied warranties of merchantability
  16. and fitness.  In no event shall AT&T or Bellcore be liable for
  17. any special, indirect or consequential damages or any damages
  18. whatsoever resulting from loss of use, data or profits, whether
  19. in an action of contract, negligence or other tortious action,
  20. arising out of or in connection with the use or performance of
  21. this software.
  22. ****************************************************************/
  23.  
  24. #include "defs.h"
  25. #include "tokdefs.h"
  26. #include "p1defs.h"
  27.  
  28. #ifdef NO_EOF_CHAR_CHECK
  29. #undef EOF_CHAR
  30. #else
  31. #ifndef EOF_CHAR
  32. #define EOF_CHAR 26    /* ASCII control-Z */
  33. #endif
  34. #endif
  35.  
  36. #define BLANK    ' '
  37. #define MYQUOTE (2)
  38. #define SEOF 0
  39.  
  40. /* card types */
  41.  
  42. #define STEOF 1
  43. #define STINITIAL 2
  44. #define STCONTINUE 3
  45.  
  46. /* lex states */
  47.  
  48. #define NEWSTMT    1
  49. #define FIRSTTOKEN    2
  50. #define OTHERTOKEN    3
  51. #define RETEOS    4
  52.  
  53.  
  54. LOCAL int stkey;    /* Type of the current statement (DO, END, IF, etc) */
  55. static int needwkey;
  56. ftnint yystno;
  57. flag intonly;
  58. extern int new_dcl;
  59. LOCAL long int stno;
  60. LOCAL long int nxtstno;    /* Statement label */
  61. LOCAL int parlev;    /* Parentheses level */
  62. LOCAL int parseen;
  63. LOCAL int expcom;
  64. LOCAL int expeql;
  65. LOCAL char *nextch;
  66. LOCAL char *lastch;
  67. LOCAL char *nextcd     = NULL;
  68. LOCAL char *endcd;
  69. LOCAL long prevlin;
  70. LOCAL long thislin;
  71. LOCAL int code;        /* Card type; INITIAL, CONTINUE or EOF */
  72. LOCAL int lexstate    = NEWSTMT;
  73. LOCAL char *sbuf;    /* Main buffer for Fortran source input. */
  74. LOCAL char *send;    /* Was = sbuf+20*66 with sbuf[1390]. */
  75. LOCAL int maxcont;
  76. LOCAL int nincl    = 0;    /* Current number of include files */
  77. LOCAL long firstline;
  78. LOCAL char *laststb, *stb0;
  79. extern int addftnsrc;
  80. static char **linestart;
  81. LOCAL int ncont;
  82. LOCAL char comstart[Table_size];
  83. #define USC (unsigned char *)
  84.  
  85. static char anum_buf[Table_size];
  86. #define isalnum_(x) anum_buf[x]
  87. #define isalpha_(x) (anum_buf[x] == 1)
  88.  
  89. #define COMMENT_BUF_STORE 4088
  90.  
  91. typedef struct comment_buf {
  92.     struct comment_buf *next;
  93.     char *last;
  94.     char buf[COMMENT_BUF_STORE];
  95.     } comment_buf;
  96. static comment_buf *cbfirst, *cbcur;
  97. static char *cbinit, *cbnext, *cblast;
  98. static void flush_comments Argdcl((void));
  99. extern flag use_bs;
  100. static char *lastfile = "??", *lastfile0 = "?";
  101. static char fbuf[P1_FILENAME_MAX];
  102. static long lastline;
  103. static void putlineno(Void);
  104.  
  105.  
  106. /* Comment buffering data
  107.  
  108.     Comments are kept in a list until the statement before them has
  109.    been parsed.  This list is implemented with the above comment_buf
  110.    structure and the pointers cbnext and cblast.
  111.  
  112.     The comments are stored with terminating NULL, and no other
  113.    intervening space.  The last few bytes of each block are likely to
  114.    remain unused.
  115. */
  116.  
  117. /* struct Inclfile   holds the state information for each include file */
  118. struct Inclfile
  119. {
  120.     struct Inclfile *inclnext;
  121.     FILEP inclfp;
  122.     char *inclname;
  123.     int incllno;
  124.     char *incllinp;
  125.     int incllen;
  126.     int inclcode;
  127.     ftnint inclstno;
  128. };
  129.  
  130. LOCAL struct Inclfile *inclp    =  NULL;
  131. struct Keylist {
  132.     char *keyname;
  133.     int keyval;
  134.     char notinf66;
  135. };
  136. struct Punctlist {
  137.     char punchar;
  138.     int punval;
  139. };
  140. struct Fmtlist {
  141.     char fmtchar;
  142.     int fmtval;
  143. };
  144. struct Dotlist {
  145.     char *dotname;
  146.     int dotval;
  147.     };
  148. LOCAL struct Keylist *keystart[26], *keyend[26];
  149.  
  150. /* KEYWORD AND SPECIAL CHARACTER TABLES
  151. */
  152.  
  153. static struct Punctlist puncts[ ] =
  154. {
  155.     '(', SLPAR,
  156.     ')', SRPAR,
  157.     '=', SEQUALS,
  158.     ',', SCOMMA,
  159.     '+', SPLUS,
  160.     '-', SMINUS,
  161.     '*', SSTAR,
  162.     '/', SSLASH,
  163.     '$', SCURRENCY,
  164.     ':', SCOLON,
  165.     '<', SLT,
  166.     '>', SGT,
  167.     0, 0 };
  168.  
  169. LOCAL struct Dotlist  dots[ ] =
  170. {
  171.     "and.", SAND,
  172.         "or.", SOR,
  173.         "not.", SNOT,
  174.         "true.", STRUE,
  175.         "false.", SFALSE,
  176.         "eq.", SEQ,
  177.         "ne.", SNE,
  178.         "lt.", SLT,
  179.         "le.", SLE,
  180.         "gt.", SGT,
  181.         "ge.", SGE,
  182.         "neqv.", SNEQV,
  183.         "eqv.", SEQV,
  184.         0, 0 };
  185.  
  186. LOCAL struct Keylist  keys[ ] =
  187. {
  188.     { "assign",  SASSIGN  },
  189.     { "automatic",  SAUTOMATIC, YES  },
  190.     { "backspace",  SBACKSPACE  },
  191.     { "blockdata",  SBLOCK  },
  192.     { "byte",    SBYTE    },
  193.     { "call",  SCALL  },
  194.     { "character",  SCHARACTER, YES  },
  195.     { "close",  SCLOSE, YES  },
  196.     { "common",  SCOMMON  },
  197.     { "complex",  SCOMPLEX  },
  198.     { "continue",  SCONTINUE  },
  199.     { "data",  SDATA  },
  200.     { "dimension",  SDIMENSION  },
  201.     { "doubleprecision",  SDOUBLE  },
  202.     { "doublecomplex", SDCOMPLEX, YES  },
  203.     { "elseif",  SELSEIF, YES  },
  204.     { "else",  SELSE, YES  },
  205.     { "endfile",  SENDFILE  },
  206.     { "endif",  SENDIF, YES  },
  207.     { "enddo", SENDDO, YES },
  208.     { "end",  SEND  },
  209.     { "entry",  SENTRY, YES  },
  210.     { "equivalence",  SEQUIV  },
  211.     { "external",  SEXTERNAL  },
  212.     { "format",  SFORMAT  },
  213.     { "function",  SFUNCTION  },
  214.     { "goto",  SGOTO  },
  215.     { "implicit",  SIMPLICIT, YES  },
  216.     { "include",  SINCLUDE, YES  },
  217.     { "inquire",  SINQUIRE, YES  },
  218.     { "intrinsic",  SINTRINSIC, YES  },
  219.     { "integer",  SINTEGER  },
  220.     { "logical",  SLOGICAL  },
  221.     { "namelist", SNAMELIST, YES },
  222.     { "none", SUNDEFINED, YES },
  223.     { "open",  SOPEN, YES  },
  224.     { "parameter",  SPARAM, YES  },
  225.     { "pause",  SPAUSE  },
  226.     { "print",  SPRINT  },
  227.     { "program",  SPROGRAM, YES  },
  228.     { "punch",  SPUNCH, YES  },
  229.     { "read",  SREAD  },
  230.     { "real",  SREAL  },
  231.     { "return",  SRETURN  },
  232.     { "rewind",  SREWIND  },
  233.     { "save",  SSAVE, YES  },
  234.     { "static",  SSTATIC, YES  },
  235.     { "stop",  SSTOP  },
  236.     { "subroutine",  SSUBROUTINE  },
  237.     { "then",  STHEN, YES  },
  238.     { "undefined", SUNDEFINED, YES  },
  239.     { "while", SWHILE, YES  },
  240.     { "write",  SWRITE  },
  241.     { 0, 0 }
  242. };
  243.  
  244. static void analyz Argdcl((void));
  245. static void crunch Argdcl((void));
  246. static int getcd Argdcl((char*, int));
  247. static int getcds Argdcl((void));
  248. static int getkwd Argdcl((void));
  249. static int gettok Argdcl((void));
  250. static void store_comment Argdcl((char*));
  251. LOCAL char *stbuf[3];
  252.  
  253.  int
  254. #ifdef KR_headers
  255. inilex(name)
  256.     char *name;
  257. #else
  258. inilex(char *name)
  259. #endif
  260. {
  261.     stbuf[0] = Alloc(3*P1_STMTBUFSIZE);
  262.     stbuf[1] = stbuf[0] + P1_STMTBUFSIZE;
  263.     stbuf[2] = stbuf[1] + P1_STMTBUFSIZE;
  264.     nincl = 0;
  265.     inclp = NULL;
  266.     doinclude(name);
  267.     lexstate = NEWSTMT;
  268.     return(NO);
  269. }
  270.  
  271.  
  272.  
  273. /* throw away the rest of the current line */
  274.  void
  275. flline(Void)
  276. {
  277.     lexstate = RETEOS;
  278. }
  279.  
  280.  
  281.  
  282.  char *
  283. #ifdef KR_headers
  284. lexline(n)
  285.     int *n;
  286. #else
  287. lexline(int *n)
  288. #endif
  289. {
  290.     *n = (lastch - nextch) + 1;
  291.     return(nextch);
  292. }
  293.  
  294.  
  295.  
  296.  
  297.  void
  298. #ifdef KR_headers
  299. doinclude(name)
  300.     char *name;
  301. #else
  302. doinclude(char *name)
  303. #endif
  304. {
  305.     FILEP fp;
  306.     struct Inclfile *t;
  307.     char *name0, *lastslash, *s, *s0, *temp;
  308.     int j, k;
  309.     chainp I;
  310.     extern chainp Iargs;
  311.  
  312.     if(inclp)
  313.     {
  314.         inclp->incllno = thislin;
  315.         inclp->inclcode = code;
  316.         inclp->inclstno = nxtstno;
  317.         if(nextcd)
  318.             inclp->incllinp = copyn(inclp->incllen = endcd-nextcd , nextcd);
  319.         else
  320.             inclp->incllinp = 0;
  321.     }
  322.     nextcd = NULL;
  323.  
  324.     if(++nincl >= MAXINCLUDES)
  325.         Fatal("includes nested too deep");
  326.     if(name[0] == '\0')
  327.         fp = stdin;
  328.     else if(name[0] == '/' || inclp == NULL
  329. #ifdef MSDOS
  330.         || name[0] == '\\'
  331.         || name[1] == ':'
  332. #endif
  333.         )
  334.         fp = fopen(name, textread);
  335.     else {
  336.         lastslash = NULL;
  337.         s = s0 = inclp->inclname;
  338. #ifdef MSDOS
  339.         if (s[1] == ':')
  340.             lastslash = s + 1;
  341. #endif
  342.         for(; *s ; ++s)
  343.             if(*s == '/'
  344. #ifdef MSDOS
  345.             || *s == '\\'
  346. #endif
  347.             )
  348.                 lastslash = s;
  349.         name0 = name;
  350.         if(lastslash) {
  351.             k = lastslash - s0 + 1;
  352.             temp = Alloc(k + strlen(name) + 1);
  353.             strncpy(temp, s0, k);
  354.             strcpy(temp+k, name);
  355.             name = temp;
  356.             }
  357.         fp = fopen(name, textread);
  358.         if (!fp && (I = Iargs)) {
  359.             k = strlen(name0) + 2;
  360.             for(; I; I = I->nextp) {
  361.                 j = strlen(s = I->datap);
  362.                 name = Alloc(j + k);
  363.                 strcpy(name, s);
  364.                 switch(s[j-1]) {
  365.                     case '/':
  366. #ifdef MSDOS
  367.                     case ':':
  368.                     case '\\':
  369. #endif
  370.                         break;
  371.                     default:
  372.                         name[j++] = '/';
  373.                     }
  374.                 strcpy(name+j, name0);
  375.                 if (fp = fopen(name, textread)) {
  376.                     free(name0);
  377.                     goto havefp;
  378.                     }
  379.                 free(name);
  380.                 name = name0;
  381.                 }
  382.             }
  383.         }
  384.     if (fp)
  385.     {
  386.  havefp:
  387.         t = inclp;
  388.         inclp = ALLOC(Inclfile);
  389.         inclp->inclnext = t;
  390.         prevlin = thislin = 0;
  391.         infname = inclp->inclname = name;
  392.         infile = inclp->inclfp = fp;
  393.         lastline = 0;
  394.         putlineno();
  395.         lastline = 0;
  396.     }
  397.     else
  398.     {
  399.         fprintf(diagfile, "Cannot open file %s\n", name);
  400.         done(1);
  401.     }
  402. }
  403.  
  404.  
  405.  
  406.  
  407.  LOCAL int
  408. popinclude(Void)
  409. {
  410.     struct Inclfile *t;
  411.     register char *p;
  412.     register int k;
  413.  
  414.     if(infile != stdin)
  415.         clf(&infile, infname, 1);    /* Close the input file */
  416.     free(infname);
  417.  
  418.     --nincl;
  419.     t = inclp->inclnext;
  420.     free( (charptr) inclp);
  421.     inclp = t;
  422.     if(inclp == NULL) {
  423.         infname = 0;
  424.         return(NO);
  425.         }
  426.  
  427.     infile = inclp->inclfp;
  428.     infname = inclp->inclname;
  429.     lineno = prevlin = thislin = inclp->incllno;
  430.     code = inclp->inclcode;
  431.     stno = nxtstno = inclp->inclstno;
  432.     if(inclp->incllinp)
  433.     {
  434.         lastline = 0;
  435.         putlineno();
  436.         lastline = lineno;
  437.         endcd = nextcd = sbuf;
  438.         k = inclp->incllen;
  439.         p = inclp->incllinp;
  440.         while(--k >= 0)
  441.             *endcd++ = *p++;
  442.         free( (charptr) (inclp->incllinp) );
  443.     }
  444.     else
  445.         nextcd = NULL;
  446.     return(YES);
  447. }
  448.  
  449.  
  450.  void
  451. #ifdef KR_headers
  452. p1_line_number(line_number)
  453.     long line_number;
  454. #else
  455. p1_line_number(long line_number)
  456. #endif
  457. {
  458.     if (lastfile != lastfile0) {
  459.         p1puts(P1_FILENAME, fbuf);
  460.         lastfile0 = lastfile;
  461.         }
  462.     fprintf(pass1_file, "%d: %ld\n", P1_SET_LINE, line_number);
  463.     }
  464.  
  465.  static void
  466. putlineno(Void)
  467. {
  468.     extern int gflag;
  469.     register char *s0, *s1;
  470.  
  471.     if (gflag) {
  472.         if (lastline)
  473.             p1_line_number(lastline);
  474.         lastline = firstline;
  475.         if (lastfile != infname)
  476.             if (lastfile = infname) {
  477.                 strncpy(fbuf, lastfile, sizeof(fbuf));
  478.                 fbuf[sizeof(fbuf)-1] = 0;
  479.                 }
  480.             else
  481.                 fbuf[0] = 0;
  482.         }
  483.     if (addftnsrc) {
  484.         if (laststb && *laststb) {
  485.             for(s1 = laststb; *s1; s1++) {
  486.                 for(s0 = s1; *s1 != '\n'; s1++)
  487.                     if (*s1 == '*' && s1[1] == '/')
  488.                         *s1 = '+';
  489.                 *s1 = 0;
  490.                 p1puts(P1_FORTRAN, s0);
  491.                 }
  492.             *laststb = 0;    /* prevent trouble after EOF */
  493.             }
  494.         laststb = stb0;
  495.         }
  496.     }
  497.  
  498.  int
  499. yylex(Void)
  500. {
  501.     static int  tokno;
  502.     int retval;
  503.  
  504.     switch(lexstate)
  505.     {
  506.     case NEWSTMT :    /* need a new statement */
  507.         retval = getcds();
  508.         putlineno();
  509.         if(retval == STEOF) {
  510.             retval = SEOF;
  511.             break;
  512.         } /* if getcds() == STEOF */
  513.         crunch();
  514.         tokno = 0;
  515.         lexstate = FIRSTTOKEN;
  516.         yystno = stno;
  517.         stno = nxtstno;
  518.         toklen = 0;
  519.         retval = SLABEL;
  520.         break;
  521.  
  522. first:
  523.     case FIRSTTOKEN :    /* first step on a statement */
  524.         analyz();
  525.         lexstate = OTHERTOKEN;
  526.         tokno = 1;
  527.         retval = stkey;
  528.         break;
  529.  
  530.     case OTHERTOKEN :    /* return next token */
  531.         if(nextch > lastch)
  532.             goto reteos;
  533.         ++tokno;
  534.         if( (stkey==SLOGIF || stkey==SELSEIF) && parlev==0 && tokno>3)
  535.             goto first;
  536.  
  537.         if(stkey==SASSIGN && tokno==3 && nextch<lastch &&
  538.             nextch[0]=='t' && nextch[1]=='o')
  539.         {
  540.             nextch+=2;
  541.             retval = STO;
  542.             break;
  543.         }
  544.         retval = gettok();
  545.         break;
  546.  
  547. reteos:
  548.     case RETEOS:
  549.         lexstate = NEWSTMT;
  550.         retval = SEOS;
  551.         break;
  552.     default:
  553.         fatali("impossible lexstate %d", lexstate);
  554.         break;
  555.     }
  556.  
  557.     if (retval == SEOF)
  558.         flush_comments ();
  559.  
  560.     return retval;
  561. }
  562.  
  563.  LOCAL void
  564. contmax(Void)
  565. {
  566.     lineno = thislin;
  567.     many("continuation lines", 'C', maxcontin);
  568.     }
  569.  
  570. /* Get Cards.
  571.  
  572.    Returns STEOF or STINITIAL, never STCONTINUE.  Any continuation cards get
  573. merged into one long card (hence the size of the buffer named   sbuf)   */
  574.  
  575.  LOCAL int
  576. getcds(Void)
  577. {
  578.     register char *p, *q;
  579.  
  580.     flush_comments ();
  581. top:
  582.     if(nextcd == NULL)
  583.     {
  584.         code = getcd( nextcd = sbuf, 1 );
  585.         stno = nxtstno;
  586.         prevlin = thislin;
  587.     }
  588.     if(code == STEOF)
  589.         if( popinclude() )
  590.             goto top;
  591.         else
  592.             return(STEOF);
  593.  
  594.     if(code == STCONTINUE)
  595.     {
  596.         lineno = thislin;
  597.         nextcd = NULL;
  598.         goto top;
  599.     }
  600.  
  601. /* Get rid of unused space at the head of the buffer */
  602.  
  603.     if(nextcd > sbuf)
  604.     {
  605.         q = nextcd;
  606.         p = sbuf;
  607.         while(q < endcd)
  608.             *p++ = *q++;
  609.         endcd = p;
  610.     }
  611.  
  612. /* Be aware that the input (i.e. the string at the address   nextcd)   is NOT
  613.    NULL-terminated */
  614.  
  615. /* This loop merges all continuations into one long statement, AND puts the next
  616.    card to be read at the end of the buffer (i.e. it stores the look-ahead card
  617.    when there's room) */
  618.  
  619.     ncont = 0;
  620.     for(;;) {
  621.         nextcd = endcd;
  622.         if (ncont >= maxcont || nextcd+66 > send)
  623.             contmax();
  624.         linestart[ncont++] = nextcd;
  625.         if ((code = getcd(nextcd,0)) != STCONTINUE)
  626.             break;
  627.         if (ncont == 20 && noextflag) {
  628.             lineno = thislin;
  629.             errext("more than 19 continuation lines");
  630.             }
  631.         }
  632.     nextch = sbuf;
  633.     lastch = nextcd - 1;
  634.  
  635.     lineno = prevlin;
  636.     prevlin = thislin;
  637.     return(STINITIAL);
  638. }
  639.  
  640.  static void
  641. #ifdef KR_headers
  642. bang(a, b, c, d, e)
  643.     char *a;
  644.     char *b;
  645.     char *c;
  646.     register char *d;
  647.     register char *e;
  648. #else
  649. bang(char *a, char *b, char *c, register char *d, register char *e)
  650. #endif
  651.         /* save ! comments */
  652. {
  653.     char buf[COMMENT_BUFFER_SIZE + 1];
  654.     register char *p, *pe;
  655.  
  656.     p = buf;
  657.     pe = buf + COMMENT_BUFFER_SIZE;
  658.     *pe = 0;
  659.     while(a < b)
  660.         if (!(*p++ = *a++))
  661.             p[-1] = 0;
  662.     if (b < c)
  663.         *p++ = '\t';
  664.     while(d < e) {
  665.         if (!(*p++ = *d++))
  666.             p[-1] = ' ';
  667.         if (p == pe) {
  668.             store_comment(buf);
  669.             p = buf;
  670.             }
  671.         }
  672.     if (p > buf) {
  673.         while(--p >= buf && *p == ' ');
  674.         p[1] = 0;
  675.         store_comment(buf);
  676.         }
  677.     }
  678.  
  679.  
  680. /* getcd - Get next input card
  681.  
  682.     This function reads the next input card from global file pointer   infile.
  683. It assumes that   b   points to currently empty storage somewhere in  sbuf  */
  684.  
  685.  LOCAL int
  686. #ifdef KR_headers
  687. getcd(b, nocont)
  688.     register char *b;
  689.     int nocont;
  690. #else
  691. getcd(register char *b, int nocont)
  692. #endif
  693. {
  694.     register int c;
  695.     register char *p, *bend;
  696.     int speclin;        /* Special line - true when the line is allowed
  697.                    to have more than 66 characters (e.g. the
  698.                    "&" shorthand for continuation, use of a "\t"
  699.                    to skip part of the label columns) */
  700.     static char a[6];    /* Statement label buffer */
  701.     static char *aend    = a+6;
  702.     static char *stb, *stbend;
  703.     static int nst;
  704.     char *atend, *endcd0;
  705.     extern int warn72;
  706.     char buf72[24];
  707.     int amp, i;
  708.     char storage[COMMENT_BUFFER_SIZE + 1];
  709.     char *pointer;
  710.     long L;
  711.  
  712. top:
  713.     endcd = b;
  714.     bend = b+66;
  715.     amp = speclin = NO;
  716.     atend = aend;
  717.  
  718. /* Handle the continuation shorthand of "&" in the first column, which stands
  719.    for "     x" */
  720.  
  721.     if( (c = getc(infile)) == '&')
  722.     {
  723.         a[0] = c;
  724.         a[1] = 0;
  725.         a[5] = 'x';
  726.         amp = speclin = YES;
  727.         bend = send;
  728.         p = aend;
  729.     }
  730.  
  731. /* Handle the Comment cards (a 'C', 'c', '*', or '!' in the first column). */
  732.  
  733.     else if(comstart[c & 0xfff])
  734.     {
  735.         if (feof (infile)
  736. #ifdef EOF_CHAR
  737.              || c == EOF_CHAR
  738. #endif
  739.                     )
  740.             return STEOF;
  741.  
  742.         if (c == '#') {
  743.             *endcd++ = c;
  744.             while((c = getc(infile)) != '\n')
  745.                 if (c == EOF)
  746.                     return STEOF;
  747.                 else if (endcd < bend)
  748.                     *endcd++ = c;
  749.             ++thislin;
  750.             *endcd = 0;
  751.             if (b[1] == ' ')
  752.                 p = b + 2;
  753.             else if (!strncmp(b,"#line ",6))
  754.                 p = b + 6;
  755.             else {
  756.  bad_cpp:
  757.                 errstr("Bad # line: \"%s\"", b);
  758.                 goto top;
  759.                 }
  760.             if (*p < '1' || *p > '9')
  761.                 goto bad_cpp;
  762.             L = *p - '0';
  763.             while((c = *++p) >= '0' && c <= '9')
  764.                 L = 10*L + c - '0';
  765.             if (c != ' ' || *++p != '"')
  766.                 goto bad_cpp;
  767.             bend = p;
  768.             while(*++p != '"')
  769.                 if (!*p)
  770.                     goto bad_cpp;
  771.             *p = 0;
  772.             i = p - bend++;
  773.             thislin = L - 1;
  774.             if (!infname || strcmp(infname, bend)) {
  775.                 if (infname)
  776.                     free(infname);
  777.                 lastfile = 0;
  778.                 infname = Alloc(i);
  779.                 strcpy(infname, bend);
  780.                 if (inclp)
  781.                     inclp->inclname = infname;
  782.                 }
  783.             goto top;
  784.             }
  785.  
  786.         storage[COMMENT_BUFFER_SIZE] = c = '\0';
  787.         pointer = storage;
  788.         while( !feof (infile) && (*pointer++ = c = getc(infile)) != '\n') {
  789.  
  790. /* Handle obscure end of file conditions on many machines */
  791.  
  792.             if (feof (infile) && (c == '\377' || c == EOF)) {
  793.                 pointer--;
  794.                 break;
  795.             } /* if (feof (infile)) */
  796.  
  797.             if (c == '\0')
  798.                 *(pointer - 1) = ' ';
  799.  
  800.             if (pointer == &storage[COMMENT_BUFFER_SIZE]) {
  801.                 store_comment (storage);
  802.                 pointer = storage;
  803.             } /* if (pointer == BUFFER_SIZE) */
  804.         } /* while */
  805.  
  806.         if (pointer > storage) {
  807.             if (c == '\n')
  808.  
  809. /* Get rid of the newline */
  810.  
  811.             pointer[-1] = 0;
  812.             else
  813.             *pointer = 0;
  814.  
  815.             store_comment (storage);
  816.         } /* if */
  817.  
  818.         if (feof (infile))
  819.             if (c != '\n')    /* To allow the line index to
  820.                        increment correctly */
  821.             return STEOF;
  822.  
  823.         ++thislin;
  824.         goto top;
  825.     }
  826.  
  827.     else if(c != EOF)
  828.     {
  829.  
  830. /* Load buffer   a   with the statement label */
  831.  
  832.         /* a tab in columns 1-6 skips to column 7 */
  833.         ungetc(c, infile);
  834.         for(p=a; p<aend && (c=getc(infile)) != '\n' && c!=EOF; )
  835.             if(c == '\t')
  836.  
  837. /* The tab character translates into blank characters in the statement label */
  838.  
  839.             {
  840.                 atend = p;
  841.                 while(p < aend)
  842.                     *p++ = BLANK;
  843.                 speclin = YES;
  844.                 bend = send;
  845.             }
  846.             else
  847.                 *p++ = c;
  848.     }
  849.  
  850. /* By now we've read either a continuation character or the statement label
  851.    field */
  852.  
  853.     if(c == EOF)
  854.         return(STEOF);
  855.  
  856. /* The next 'if' block handles lines that have fewer than 7 characters */
  857.  
  858.     if(c == '\n')
  859.     {
  860.         while(p < aend)
  861.             *p++ = BLANK;
  862.  
  863. /* Blank out the buffer on lines which are not longer than 66 characters */
  864.  
  865.         endcd0 = endcd;
  866.         if( ! speclin )
  867.             while(endcd < bend)
  868.                 *endcd++ = BLANK;
  869.     }
  870.     else    {    /* read body of line */
  871.         if (warn72 & 2) {
  872.             speclin = YES;
  873.             bend = send;
  874.             }
  875.         while( endcd<bend && (c=getc(infile)) != '\n' && c!=EOF )
  876.             *endcd++ = c;
  877.         if(c == EOF)
  878.             return(STEOF);
  879.  
  880. /* Drop any extra characters on the input card; this usually means those after
  881.    column 72 */
  882.  
  883.         if(c != '\n')
  884.         {
  885.             i = 0;
  886.             while( (c=getc(infile)) != '\n' && c != EOF)
  887.                 if (i < 23)
  888.                     buf72[i++] = c;
  889.             if (warn72 && i && !speclin) {
  890.                 buf72[i] = 0;
  891.                 if (i >= 23)
  892.                     strcpy(buf72+20, "...");
  893.                 lineno = thislin + 1;
  894.                 errstr("text after column 72: %s", buf72);
  895.                 }
  896.             if(c == EOF)
  897.                 return(STEOF);
  898.         }
  899.  
  900.         endcd0 = endcd;
  901.         if( ! speclin )
  902.             while(endcd < bend)
  903.                 *endcd++ = BLANK;
  904.     }
  905.  
  906. /* The flow of control usually gets to this line (unless an earlier RETURN has
  907.    been taken) */
  908.  
  909.     ++thislin;
  910.  
  911.     /* Fortran 77 specifies that a 0 in column 6 */
  912.     /* does not signify continuation */
  913.  
  914.     if( !isspace(a[5]) && a[5]!='0') {
  915.         if (!amp)
  916.             for(p = a; p < aend;)
  917.                 if (*p++ == '!' && p != aend)
  918.                     goto initcheck;
  919.         if (addftnsrc && stb) {
  920.             if (stbend > stb + 7) { /* otherwise forget col 1-6 */
  921.                 /* kludge around funny p1gets behavior */
  922.                 *stb++ = '$';
  923.                 if (amp)
  924.                     *stb++ = '&';
  925.                 else
  926.                     for(p = a; p < atend;)
  927.                         *stb++ = *p++;
  928.                 }
  929.             if (endcd0 - b > stbend - stb) {
  930.                 if (stb > stbend)
  931.                     stb = stbend;
  932.                 endcd0 = b + (stbend - stb);
  933.                 }
  934.             for(p = b; p < endcd0;)
  935.                 *stb++ = *p++;
  936.             *stb++ = '\n';
  937.             *stb = 0;
  938.             }
  939.         if (nocont) {
  940.             lineno = thislin;
  941.             errstr("illegal continuation card (starts \"%.6s\")",a);
  942.             }
  943.         else if (!amp && strncmp(a,"     ",5)) {
  944.             lineno = thislin;
  945.             errstr("labeled continuation line (starts \"%.6s\")",a);
  946.             }
  947.         return(STCONTINUE);
  948.         }
  949. initcheck:
  950.     for(p=a; p<atend; ++p)
  951.         if( !isspace(*p) ) {
  952.             if (*p++ != '!')
  953.                 goto initline;
  954.             bang(p, atend, aend, b, endcd);
  955.             goto top;
  956.             }
  957.     for(p = b ; p<endcd ; ++p)
  958.         if( !isspace(*p) ) {
  959.             if (*p++ != '!')
  960.                 goto initline;
  961.             bang(a, a, a, p, endcd);
  962.             goto top;
  963.             }
  964.  
  965. /* Skip over blank cards by reading the next one right away */
  966.  
  967.     goto top;
  968.  
  969. initline:
  970.     if (!lastline)
  971.         lastline = thislin;
  972.     if (addftnsrc) {
  973.         nst = (nst+1)%3;
  974.         if (!laststb && stb0)
  975.             laststb = stb0;
  976.         stb0 = stb = stbuf[nst];
  977.         *stb++ = '$';    /* kludge around funny p1gets behavior */
  978.         stbend = stb + sizeof(stbuf[0])-2;
  979.         for(p = a; p < atend;)
  980.             *stb++ = *p++;
  981.         if (atend < aend)
  982.             *stb++ = '\t';
  983.         for(p = b; p < endcd0;)
  984.             *stb++ = *p++;
  985.         *stb++ = '\n';
  986.         *stb = 0;
  987.         }
  988.  
  989. /* Set   nxtstno   equal to the integer value of the statement label */
  990.  
  991.     nxtstno = 0;
  992.     bend = a + 5;
  993.     for(p = a ; p < bend ; ++p)
  994.         if( !isspace(*p) )
  995.             if(isdigit(*p))
  996.                 nxtstno = 10*nxtstno + (*p - '0');
  997.             else if (*p == '!') {
  998.                 if (!addftnsrc)
  999.                     bang(p+1,atend,aend,b,endcd);
  1000.                 endcd = b;
  1001.                 break;
  1002.                 }
  1003.             else    {
  1004.                 lineno = thislin;
  1005.                 errstr(
  1006.                 "nondigit in statement label field \"%.5s\"", a);
  1007.                 nxtstno = 0;
  1008.                 break;
  1009.             }
  1010.     firstline = thislin;
  1011.     return(STINITIAL);
  1012. }
  1013.  
  1014.  LOCAL void
  1015. #ifdef KR_headers
  1016. adjtoklen(newlen)
  1017.     int newlen;
  1018. #else
  1019. adjtoklen(int newlen)
  1020. #endif
  1021. {
  1022.     while(maxtoklen < newlen)
  1023.         maxtoklen = 2*maxtoklen + 2;
  1024.     if (token = (char *)realloc(token, maxtoklen))
  1025.         return;
  1026.     fprintf(stderr, "adjtoklen: realloc(%d) failure!\n", maxtoklen);
  1027.     exit(2);
  1028.     }
  1029.  
  1030. /* crunch -- deletes all space characters, folds the backslash chars and
  1031.    Hollerith strings, quotes the Fortran strings */
  1032.  
  1033.  LOCAL void
  1034. crunch(Void)
  1035. {
  1036.     register char *i, *j, *j0, *j1, *prvstr;
  1037.     int k, ten, nh, nh0, quote;
  1038.  
  1039.     /* i is the next input character to be looked at
  1040.        j is the next output character */
  1041.  
  1042.     new_dcl = needwkey = parlev = parseen = 0;
  1043.     expcom = 0;    /* exposed ','s */
  1044.     expeql = 0;    /* exposed equal signs */
  1045.     j = sbuf;
  1046.     prvstr = sbuf;
  1047.     k = 0;
  1048.     for(i=sbuf ; i<=lastch ; ++i)
  1049.     {
  1050.         if(isspace(*i) )
  1051.             continue;
  1052.         if (*i == '!') {
  1053.             while(i >= linestart[k])
  1054.                 if (++k >= maxcont)
  1055.                     contmax();
  1056.             j0 = linestart[k];
  1057.             if (!addftnsrc)
  1058.                 bang(sbuf,sbuf,sbuf,i+1,j0);
  1059.             i = j0-1;
  1060.             continue;
  1061.             }
  1062.  
  1063. /* Keep everything in a quoted string */
  1064.  
  1065.         if(*i=='\'' ||  *i=='"')
  1066.         {
  1067.             int len = 0;
  1068.  
  1069.             quote = *i;
  1070.             *j = MYQUOTE; /* special marker */
  1071.             for(;;)
  1072.             {
  1073.                 if(++i > lastch)
  1074.                 {
  1075.                     err("unbalanced quotes; closing quote supplied");
  1076.                     if (j >= lastch)
  1077.                         j = lastch - 1;
  1078.                     break;
  1079.                 }
  1080.                 if(*i == quote)
  1081.                     if(i<lastch && i[1]==quote) ++i;
  1082.                     else break;
  1083.                 else if(*i=='\\' && i<lastch && use_bs) {
  1084.                     ++i;
  1085.                     *i = escapes[*(unsigned char *)i];
  1086.                     }
  1087.                 *++j = *i;
  1088.                 len++;
  1089.             } /* for (;;) */
  1090.  
  1091.             if ((len = j - sbuf) > maxtoklen)
  1092.                 adjtoklen(len);
  1093.             j[1] = MYQUOTE;
  1094.             j += 2;
  1095.             prvstr = j;
  1096.         }
  1097.         else if( (*i=='h' || *i=='H')  && j>prvstr)    /* test for Hollerith strings */
  1098.         {
  1099.             j0 = j - 1;
  1100.             if( ! isdigit(*j0)) goto copychar;
  1101.             nh = *j0 - '0';
  1102.             ten = 10;
  1103.             j1 = prvstr;
  1104.             if (j1+4 < j)
  1105.                 j1 = j-4;
  1106.             for(;;) {
  1107.                 if (j0-- <= j1)
  1108.                     goto copychar;
  1109.                 if( ! isdigit(*j0 ) ) break;
  1110.                 nh += ten * (*j0-'0');
  1111.                 ten*=10;
  1112.                 }
  1113.             /* a hollerith must be preceded by a punctuation mark.
  1114.    '*' is possible only as repetition factor in a data statement
  1115.    not, in particular, in character*2h
  1116. */
  1117.  
  1118.             if( !(*j0=='*'&&sbuf[0]=='d') && *j0!='/'
  1119.             && *j0!='(' && *j0!=',' && *j0!='=' && *j0!='.')
  1120.                 goto copychar;
  1121.             nh0 = nh;
  1122.             if(i+nh > lastch)
  1123.             {
  1124.                 erri("%dH too big", nh);
  1125.                 nh = lastch - i;
  1126.                 nh0 = -1;
  1127.             }
  1128.             if (nh > maxtoklen)
  1129.                 adjtoklen(nh);
  1130.             j0[1] = MYQUOTE; /* special marker */
  1131.             j = j0 + 1;
  1132.             while(nh-- > 0)
  1133.             {
  1134.                 if (++i > lastch) {
  1135.  hol_overflow:
  1136.                     if (nh0 >= 0)
  1137.                       erri("escapes make %dH too big",
  1138.                         nh0);
  1139.                     break;
  1140.                     }
  1141.                 if(*i == '\\' && use_bs) {
  1142.                     if (++i > lastch)
  1143.                         goto hol_overflow;
  1144.                     *i = escapes[*(unsigned char *)i];
  1145.                     }
  1146.                 *++j = *i;
  1147.             }
  1148.             j[1] = MYQUOTE;
  1149.             j+=2;
  1150.             prvstr = j;
  1151.         }
  1152.         else    {
  1153.             if(*i == '(') parseen = ++parlev;
  1154.             else if(*i == ')') --parlev;
  1155.             else if(parlev == 0)
  1156.                 if(*i == '=') expeql = 1;
  1157.                 else if(*i == ',') expcom = 1;
  1158. copychar:        /*not a string or space -- copy, shifting case if necessary */
  1159.             if(shiftcase && isupper(*i))
  1160.                 *j++ = tolower(*i);
  1161.             else    *j++ = *i;
  1162.         }
  1163.     }
  1164.     lastch = j - 1;
  1165.     nextch = sbuf;
  1166. }
  1167.  
  1168.  LOCAL void
  1169. analyz(Void)
  1170. {
  1171.     register char *i;
  1172.  
  1173.     if(parlev != 0)
  1174.     {
  1175.         err("unbalanced parentheses, statement skipped");
  1176.         stkey = SUNKNOWN;
  1177.         lastch = sbuf - 1; /* prevent double error msg */
  1178.         return;
  1179.     }
  1180.     if(nextch+2<=lastch && nextch[0]=='i' && nextch[1]=='f' && nextch[2]=='(')
  1181.     {
  1182.         /* assignment or if statement -- look at character after balancing paren */
  1183.         parlev = 1;
  1184.         for(i=nextch+3 ; i<=lastch; ++i)
  1185.             if(*i == (MYQUOTE))
  1186.             {
  1187.                 while(*++i != MYQUOTE)
  1188.                     ;
  1189.             }
  1190.             else if(*i == '(')
  1191.                 ++parlev;
  1192.             else if(*i == ')')
  1193.             {
  1194.                 if(--parlev == 0)
  1195.                     break;
  1196.             }
  1197.         if(i >= lastch)
  1198.             stkey = SLOGIF;
  1199.         else if(i[1] == '=')
  1200.             stkey = SLET;
  1201.         else if( isdigit(i[1]) )
  1202.             stkey = SARITHIF;
  1203.         else    stkey = SLOGIF;
  1204.         if(stkey != SLET)
  1205.             nextch += 2;
  1206.     }
  1207.     else if(expeql) /* may be an assignment */
  1208.     {
  1209.         if(expcom && nextch<lastch &&
  1210.             nextch[0]=='d' && nextch[1]=='o')
  1211.         {
  1212.             stkey = SDO;
  1213.             nextch += 2;
  1214.         }
  1215.         else    stkey = SLET;
  1216.     }
  1217.     else if (parseen && nextch + 7 < lastch
  1218.             && nextch[2] != 'u' /* screen out "double..." early */
  1219.             && nextch[0] == 'd' && nextch[1] == 'o'
  1220.             && ((nextch[2] >= '0' && nextch[2] <= '9')
  1221.                 || nextch[2] == ','
  1222.                 || nextch[2] == 'w'))
  1223.         {
  1224.         stkey = SDO;
  1225.         nextch += 2;
  1226.         needwkey = 1;
  1227.         }
  1228.     /* otherwise search for keyword */
  1229.     else    {
  1230.         stkey = getkwd();
  1231.         if(stkey==SGOTO && lastch>=nextch)
  1232.             if(nextch[0]=='(')
  1233.                 stkey = SCOMPGOTO;
  1234.             else if(isalpha_(* USC nextch))
  1235.                 stkey = SASGOTO;
  1236.     }
  1237.     parlev = 0;
  1238. }
  1239.  
  1240.  
  1241.  
  1242.  LOCAL int
  1243. getkwd(Void)
  1244. {
  1245.     register char *i, *j;
  1246.     register struct Keylist *pk, *pend;
  1247.     int k;
  1248.  
  1249.     if(! isalpha_(* USC nextch) )
  1250.         return(SUNKNOWN);
  1251.     k = letter(nextch[0]);
  1252.     if(pk = keystart[k])
  1253.         for(pend = keyend[k] ; pk<=pend ; ++pk )
  1254.         {
  1255.             i = pk->keyname;
  1256.             j = nextch;
  1257.             while(*++i==*++j && *i!='\0')
  1258.                 ;
  1259.             if(*i=='\0' && j<=lastch+1)
  1260.             {
  1261.                 nextch = j;
  1262.                 if(no66flag && pk->notinf66)
  1263.                     errstr("Not a Fortran 66 keyword: %s",
  1264.                         pk->keyname);
  1265.                 return(pk->keyval);
  1266.             }
  1267.         }
  1268.     return(SUNKNOWN);
  1269. }
  1270.  
  1271.  void
  1272. initkey(Void)
  1273. {
  1274.     register struct Keylist *p;
  1275.     register int i,j;
  1276.     register char *s;
  1277.  
  1278.     for(i = 0 ; i<26 ; ++i)
  1279.         keystart[i] = NULL;
  1280.  
  1281.     for(p = keys ; p->keyname ; ++p) {
  1282.         j = letter(p->keyname[0]);
  1283.         if(keystart[j] == NULL)
  1284.             keystart[j] = p;
  1285.         keyend[j] = p;
  1286.         }
  1287.     i = (maxcontin + 2) * 66;
  1288.     sbuf = (char *)ckalloc(i + 70);
  1289.     send = sbuf + i;
  1290.     maxcont = maxcontin + 1;
  1291.     linestart = (char **)ckalloc(maxcont*sizeof(char*));
  1292.     comstart['c'] = comstart['C'] = comstart['*'] = comstart['!'] =
  1293.     comstart['#'] = 1;
  1294. #ifdef EOF_CHAR
  1295.     comstart[EOF_CHAR] = 1;
  1296. #endif
  1297.     s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  1298.     while(i = *s++)
  1299.         anum_buf[i] = 1;
  1300.     s = "0123456789";
  1301.     while(i = *s++)
  1302.         anum_buf[i] = 2;
  1303.     }
  1304.  
  1305.  LOCAL int
  1306. #ifdef KR_headers
  1307. hexcheck(key)
  1308.     int key;
  1309. #else
  1310. hexcheck(int key)
  1311. #endif
  1312. {
  1313.     register int radix;
  1314.     register char *p;
  1315.     char *kind;
  1316.  
  1317.     switch(key) {
  1318.         case 'z':
  1319.         case 'Z':
  1320.         case 'x':
  1321.         case 'X':
  1322.             radix = 16;
  1323.             key = SHEXCON;
  1324.             kind = "hexadecimal";
  1325.             break;
  1326.         case 'o':
  1327.         case 'O':
  1328.             radix = 8;
  1329.             key = SOCTCON;
  1330.             kind = "octal";
  1331.             break;
  1332.         case 'b':
  1333.         case 'B':
  1334.             radix = 2;
  1335.             key = SBITCON;
  1336.             kind = "binary";
  1337.             break;
  1338.         default:
  1339.             err("bad bit identifier");
  1340.             return(SNAME);
  1341.         }
  1342.     for(p = token; *p; p++)
  1343.         if (hextoi(*p) >= radix) {
  1344.             errstr("invalid %s character", kind);
  1345.             break;
  1346.             }
  1347.     return key;
  1348.     }
  1349.  
  1350. /* gettok -- moves the right amount of text from   nextch   into the   token
  1351.    buffer.   token   initially contains garbage (leftovers from the prev token) */
  1352.  
  1353.  LOCAL int
  1354. gettok(Void)
  1355. {
  1356.     int havdot, havexp, havdbl;
  1357.     int radix, val;
  1358.     struct Punctlist *pp;
  1359.     struct Dotlist *pd;
  1360.     register int ch;
  1361.  
  1362.     char *i, *j, *n1, *p;
  1363.  
  1364.     ch = * USC nextch;
  1365.     if(ch == (MYQUOTE))
  1366.     {
  1367.         ++nextch;
  1368.         p = token;
  1369.         while(*nextch != MYQUOTE)
  1370.             *p++ = *nextch++;
  1371.         toklen = p - token;
  1372.         *p = 0;
  1373.         /* allow octal, binary, hex constants of the form 'abc'x (etc.) */
  1374.         if (++nextch <= lastch && isalpha_(val = * USC nextch)) {
  1375.             ++nextch;
  1376.             return hexcheck(val);
  1377.             }
  1378.         return (SHOLLERITH);
  1379.     }
  1380.  
  1381.     if(needkwd)
  1382.     {
  1383.         needkwd = 0;
  1384.         return( getkwd() );
  1385.     }
  1386.  
  1387.     for(pp=puncts; pp->punchar; ++pp)
  1388.         if(ch == pp->punchar) {
  1389.             val = pp->punval;
  1390.             if (++nextch <= lastch)
  1391.                 switch(ch) {
  1392.                 case '/':
  1393.                     if (*nextch == '/') {
  1394.                         nextch++;
  1395.                         val = SCONCAT;
  1396.                         }
  1397.                     else if (new_dcl && parlev == 0)
  1398.                         val = SSLASHD;
  1399.                     return val;
  1400.                 case '*':
  1401.                     if (*nextch == '*') {
  1402.                         nextch++;
  1403.                         return SPOWER;
  1404.                         }
  1405.                     break;
  1406.                 case '<':
  1407.                     if (*nextch == '=') {
  1408.                         nextch++;
  1409.                         val = SLE;
  1410.                         }
  1411.                     if (*nextch == '>') {
  1412.                         nextch++;
  1413.                         val = SNE;
  1414.                         }
  1415.                     goto extchk;
  1416.                 case '=':
  1417.                     if (*nextch == '=') {
  1418.                         nextch++;
  1419.                         val = SEQ;
  1420.                         goto extchk;
  1421.                         }
  1422.                     break;
  1423.                 case '>':
  1424.                     if (*nextch == '=') {
  1425.                         nextch++;
  1426.                         val = SGE;
  1427.                         }
  1428.  extchk:
  1429.                     NOEXT("Fortran 8x comparison operator");
  1430.                     return val;
  1431.                 }
  1432.             else if (ch == '/' && new_dcl && parlev == 0)
  1433.                 return SSLASHD;
  1434.             switch(val) {
  1435.                 case SLPAR:
  1436.                     ++parlev;
  1437.                     break;
  1438.                 case SRPAR:
  1439.                     --parlev;
  1440.                 }
  1441.             return(val);
  1442.             }
  1443.     if(ch == '.')
  1444.         if(nextch >= lastch) goto badchar;
  1445.         else if(isdigit(nextch[1])) goto numconst;
  1446.         else    {
  1447.             for(pd=dots ; (j=pd->dotname) ; ++pd)
  1448.             {
  1449.                 for(i=nextch+1 ; i<=lastch ; ++i)
  1450.                     if(*i != *j) break;
  1451.                     else if(*i != '.') ++j;
  1452.                     else    {
  1453.                         nextch = i+1;
  1454.                         return(pd->dotval);
  1455.                     }
  1456.             }
  1457.             goto badchar;
  1458.         }
  1459.     if( isalpha_(ch) )
  1460.     {
  1461.         p = token;
  1462.         *p++ = *nextch++;
  1463.         while(nextch<=lastch)
  1464.             if( isalnum_(* USC nextch) )
  1465.                 *p++ = *nextch++;
  1466.             else break;
  1467.         toklen = p - token;
  1468.         *p = 0;
  1469.         if (needwkey) {
  1470.             needwkey = 0;
  1471.             if (toklen == 5
  1472.                 && nextch <= lastch && *nextch == '(' /*)*/
  1473.                 && !strcmp(token,"while"))
  1474.             return(SWHILE);
  1475.             }
  1476.         if(inioctl && nextch<=lastch && *nextch=='=')
  1477.         {
  1478.             ++nextch;
  1479.             return(SNAMEEQ);
  1480.         }
  1481.         if(toklen>8 && eqn(8,token,"function")
  1482.         && isalpha_(* USC (token+8)) &&
  1483.             nextch<lastch && nextch[0]=='(' &&
  1484.             (nextch[1]==')' || isalpha_(* USC (nextch+1))) )
  1485.         {
  1486.             nextch -= (toklen - 8);
  1487.             return(SFUNCTION);
  1488.         }
  1489.  
  1490.         if(toklen > 50)
  1491.         {
  1492.             char buff[100];
  1493.             sprintf(buff, toklen >= 60
  1494.                 ? "name %.56s... too long, truncated to %.*s"
  1495.                 : "name %s too long, truncated to %.*s",
  1496.                 token, 50, token);
  1497.             err(buff);
  1498.             toklen = 50;
  1499.             token[50] = '\0';
  1500.         }
  1501.         if(toklen==1 && *nextch==MYQUOTE) {
  1502.             val = token[0];
  1503.             ++nextch;
  1504.             for(p = token ; *nextch!=MYQUOTE ; )
  1505.                 *p++ = *nextch++;
  1506.             ++nextch;
  1507.             toklen = p - token;
  1508.             *p = 0;
  1509.             return hexcheck(val);
  1510.         }
  1511.         return(SNAME);
  1512.     }
  1513.  
  1514.     if (isdigit(ch)) {
  1515.  
  1516.         /* Check for NAG's special hex constant */
  1517.  
  1518.         if (nextch[1] == '#' && nextch < lastch
  1519.         ||  nextch[2] == '#' && isdigit(nextch[1]
  1520.                      && lastch - nextch >= 2)) {
  1521.  
  1522.             radix = atoi (nextch);
  1523.             if (*++nextch != '#')
  1524.             nextch++;
  1525.             if (radix != 2 && radix != 8 && radix != 16) {
  1526.                 erri("invalid base %d for constant, defaulting to hex",
  1527.                 radix);
  1528.             radix = 16;
  1529.             } /* if */
  1530.             if (++nextch > lastch)
  1531.             goto badchar;
  1532.             for (p = token; hextoi(*nextch) < radix;) {
  1533.             *p++ = *nextch++;
  1534.             if (nextch > lastch)
  1535.                 break;
  1536.             }
  1537.             toklen = p - token;
  1538.             *p = 0;
  1539.             return (radix == 16) ? SHEXCON : ((radix == 8) ? SOCTCON :
  1540.                 SBITCON);
  1541.             }
  1542.         }
  1543.     else
  1544.         goto badchar;
  1545. numconst:
  1546.     havdot = NO;
  1547.     havexp = NO;
  1548.     havdbl = NO;
  1549.     for(n1 = nextch ; nextch<=lastch ; ++nextch)
  1550.     {
  1551.         if(*nextch == '.')
  1552.             if(havdot) break;
  1553.             else if(nextch+2<=lastch && isalpha_(* USC (nextch+1))
  1554.                 && isalpha_(* USC (nextch+2)))
  1555.                 break;
  1556.             else    havdot = YES;
  1557.         else if( !intonly && (*nextch=='d' || *nextch=='e') )
  1558.         {
  1559.             p = nextch;
  1560.             havexp = YES;
  1561.             if(*nextch == 'd')
  1562.                 havdbl = YES;
  1563.             if(nextch<lastch)
  1564.                 if(nextch[1]=='+' || nextch[1]=='-')
  1565.                     ++nextch;
  1566.             if( ! isdigit(*++nextch) )
  1567.             {
  1568.                 nextch = p;
  1569.                 havdbl = havexp = NO;
  1570.                 break;
  1571.             }
  1572.             for(++nextch ;
  1573.                 nextch<=lastch && isdigit(* USC nextch);
  1574.                 ++nextch);
  1575.             break;
  1576.         }
  1577.         else if( ! isdigit(* USC nextch) )
  1578.             break;
  1579.     }
  1580.     p = token;
  1581.     i = n1;
  1582.     while(i < nextch)
  1583.         *p++ = *i++;
  1584.     toklen = p - token;
  1585.     *p = 0;
  1586.     if(havdbl) return(SDCON);
  1587.     if(havdot || havexp) return(SRCON);
  1588.     return(SICON);
  1589. badchar:
  1590.     sbuf[0] = *nextch++;
  1591.     return(SUNKNOWN);
  1592. }
  1593.  
  1594. /* Comment buffering code */
  1595.  
  1596.  static void
  1597. #ifdef KR_headers
  1598. store_comment(str)
  1599.     char *str;
  1600. #else
  1601. store_comment(char *str)
  1602. #endif
  1603. {
  1604.     int len;
  1605.     comment_buf *ncb;
  1606.  
  1607.     if (nextcd == sbuf) {
  1608.         flush_comments();
  1609.         p1_comment(str);
  1610.         return;
  1611.         }
  1612.     len = strlen(str) + 1;
  1613.     if (cbnext + len > cblast) {
  1614.         if (!cbcur || !(ncb = cbcur->next)) {
  1615.             ncb = (comment_buf *) Alloc(sizeof(comment_buf));
  1616.             if (cbcur) {
  1617.                 cbcur->last = cbnext;
  1618.                 cbcur->next = ncb;
  1619.                 }
  1620.             else {
  1621.                 cbfirst = ncb;
  1622.                 cbinit = ncb->buf;
  1623.                 }
  1624.             ncb->next = 0;
  1625.             }
  1626.         cbcur = ncb;
  1627.         cbnext = ncb->buf;
  1628.         cblast = cbnext + COMMENT_BUF_STORE;
  1629.         }
  1630.     strcpy(cbnext, str);
  1631.     cbnext += len;
  1632.     }
  1633.  
  1634.  static void
  1635. flush_comments(Void)
  1636. {
  1637.     register char *s, *s1;
  1638.     register comment_buf *cb;
  1639.     if (cbnext == cbinit)
  1640.         return;
  1641.     cbcur->last = cbnext;
  1642.     for(cb = cbfirst;; cb = cb->next) {
  1643.         for(s = cb->buf; s < cb->last; s = s1) {
  1644.             /* compute s1 = new s value first, since */
  1645.             /* p1_comment may insert nulls into s */
  1646.             s1 = s + strlen(s) + 1;
  1647.             p1_comment(s);
  1648.             }
  1649.         if (cb == cbcur)
  1650.             break;
  1651.         }
  1652.     cbcur = cbfirst;
  1653.     cbnext = cbinit;
  1654.     cblast = cbnext + COMMENT_BUF_STORE;
  1655.     }
  1656.  
  1657.  void
  1658. unclassifiable(Void)
  1659. {
  1660.     register char *s, *se;
  1661.  
  1662.     s = sbuf;
  1663.     se = lastch;
  1664.     if (se < sbuf)
  1665.         return;
  1666.     lastch = s - 1;
  1667.     if (se - s > 10)
  1668.         se = s + 10;
  1669.     for(; s < se; s++)
  1670.         if (*s == MYQUOTE) {
  1671.             se = s;
  1672.             break;
  1673.             }
  1674.     *se = 0;
  1675.     errstr("unclassifiable statement (starts \"%s\")", sbuf);
  1676.     }
  1677.